﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Diagnostics;

namespace SwHelper
{
    public class SwAppHelper
    {
        public SldWorks CreateSwApp()
        {    
            SldWorks swApp = new SldWorks();
            swApp.Visible = true;
            return swApp;
        }
        

        public SldWorks GetSwApp()
        {
            SldWorks swApp = null;
            bool isActive = false;
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            foreach (Process thisProc in Process.GetProcessesByName("SLDWORKS"))
            {
                isActive = true;
                break;
            }
            if (isActive)
            {
 
                    System.Type swType = System.Type.GetTypeFromProgID("SldWorks.Application");
                    swApp = System.Activator.CreateInstance(swType) as SldWorks;  
                    //ModelDoc2 modelDoc1 = swApp.IActiveDoc2;
            }
            else
            {
                swApp = CreateSwApp();
            }
            return swApp;
        }
    }
}
